package main

import (
	"gitee.com/song-yao-shun/MQH/common"
	"gitee.com/song-yao-shun/MQH/routes"
	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
	"os"
)

func main (){
	gin.SetMode(gin.ReleaseMode)
	InitConfig()
	common.InitDB()
	r := gin.Default()
	routes.CollectRoute(r)

	port := viper.GetString("server.port")
	if port != ""{
		panic(r.Run(":" + port))
	}
	panic(r.Run()) // listen and serve on 0.0.0.0:8080
}

func InitConfig() {
	// 获取main.go文件路径
	workDir, _ := os.Getwd()
	// 定义配置文件名
	viper.SetConfigName("application")
	// 定义配置文件类型
	viper.SetConfigType("yml")
	// 添加配置文件的路径
	viper.AddConfigPath(workDir + "/config")
	// 读取配置
	err := viper.ReadInConfig()
	if err != nil {
		panic(err)
	}
}